package com.example.demo1.service;

import com.example.demo1.Entity.AdminCourse;
import com.example.demo1.repository.AdminCourseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.converter.json.GsonBuilderUtils;
import org.springframework.transaction.annotation.Transactional;

public class AdminCourseServiceImpl implements AdminCourseService{
    @Autowired
    private AdminCourseRepository adminCourseRepository;
    @Transactional
    @Override
    public AdminCourse AdminCourseSet(String coursename,
                                      Long   courseid,
                                        String teachername){
                AdminCourse adminCourse=new AdminCourse();
                adminCourse.setCourseid(courseid);
                adminCourse.setCoursename(coursename);
                adminCourse.setTeachername(teachername);
                return adminCourse;
    }
    @Transactional
    public void save_data(AdminCourse D){
        adminCourseRepository.save(D);
        System.out.println("插入成功：ID"+D.getId());
    }
    public AdminCourse getAdminCourseByCourseId(String coursename ){

        return adminCourseRepository.findByCoursename(coursename).orElse(null);
    }
}
